package logic

import (
	"MyBlogv2/Servers/Article/article"
	"MyBlogv2/Servers/Article/internal/svc"
	"MyBlogv2/blog-common/HttpCode"
	"MyBlogv2/blog-common/models"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateArticleIsTopLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateArticleIsTopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateArticleIsTopLogic {
	return &UpdateArticleIsTopLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateArticleIsTopLogic) UpdateArticleIsTop(in *Article.UpdateArticleIsTopRequest) (*Article.CommonResponse, error) {
	id := in.Id
	isTop := in.IsTop
	models.Db.Model(new(models.Article)).Where("id = ?", id).Update("is_top", isTop)
	return &Article.CommonResponse{
		Code: int64(HttpCode.SUCCESS),
	}, nil
}
